#include <QApplication>
#include "myitem.h"
#include "myview.h"
#include "myscene.h"
#include <QTime>

#include <QLabel>
#include <QCheckBox>
#include <QLineEdit>
#include <QPushButton>
#include <QGraphicsProxyWidget>
#include <QGraphicsGridLayout>

int main(int argc,char* argv[ ])
{
    QApplication app(argc,argv);

    qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime()));

    MyScene scene;
    scene.setSceneRect(-200, -150, 400, 300);
    for(int i = 0; i < 5; ++i) {
        MyItem *item = new MyItem;
        item->setColor(QColor(qrand() % 256, qrand() % 256, qrand() % 256));
        item->setPos(i * 50 - 90, -50);
        scene.addItem(item);
    }


    MyView view;
    view.setScene(&scene);
    view.setFocusPolicy(Qt::NoFocus);
//    view.setBackgroundBrush(QPixmap(":/background.png"));
    view.setBackgroundBrush(Qt::black);
    view.show();

    // 创建 widget
//    QLabel *pPixmapLabel = new QLabel();
//    QLineEdit *pAccountLineEdit = new QLineEdit();
//    QLineEdit *pPasswdLineEdit = new QLineEdit();
//    QCheckBox *pRememberCheckBox = new QCheckBox();
//    QCheckBox *pAutoLoginCheckBox = new QCheckBox();
//    QPushButton *pLoginButton = new QPushButton();
//    QPushButton *pRegisterButton = new QPushButton();
//    QPushButton *pForgotButton = new QPushButton();

//    pPixmapLabel->setStyleSheet("border-image: url(:/Images/logo); min-width:90px; min-height:90px; border-radius:45px; background:transparent;");
//    pAccountLineEdit->setPlaceholderText(QStringLiteral("QQ号码/手机/邮箱"));
//    pPasswdLineEdit->setPlaceholderText(QStringLiteral("密码"));
//    pPasswdLineEdit->setEchoMode(QLineEdit::Password);
//    pRememberCheckBox->setText(QStringLiteral("记住密码"));
//    pAutoLoginCheckBox->setText(QStringLiteral("自动登录"));
//    pLoginButton->setText(QStringLiteral("登录"));
//    pRegisterButton->setText(QStringLiteral("注册账号"));
//    pForgotButton->setText(QStringLiteral("找回密码"));

//    pLoginButton->setFixedHeight(30);
//    pAccountLineEdit->setFixedWidth(180);

//    // 添加 widget
//    QGraphicsScene *pScene = new QGraphicsScene();
//    QGraphicsProxyWidget *pPixmapWidget = pScene->addWidget(pPixmapLabel);
//    QGraphicsProxyWidget *pAccountWidget = pScene->addWidget(pAccountLineEdit);
//    QGraphicsProxyWidget *pPasswdWidget = pScene->addWidget(pPasswdLineEdit);
//    QGraphicsProxyWidget *pRememberWidget = pScene->addWidget(pRememberCheckBox);
//    QGraphicsProxyWidget *pAutoLoginWidget = pScene->addWidget(pAutoLoginCheckBox);
//    QGraphicsProxyWidget *pLoginWidget = pScene->addWidget(pLoginButton);
//    QGraphicsProxyWidget *pRegisterWidget = pScene->addWidget(pRegisterButton);
//    QGraphicsProxyWidget *pForgotWidget = pScene->addWidget(pForgotButton);

//    // 添加至网格布局中
//    QGraphicsGridLayout *pLayout = new QGraphicsGridLayout();
//    pLayout->addItem(pPixmapWidget, 0, 0, 3, 1);
//    pLayout->addItem(pAccountWidget, 0, 1, 1, 2);
//    pLayout->addItem(pRegisterWidget, 0, 4);
//    pLayout->addItem(pPasswdWidget, 1, 1, 1, 2);
//    pLayout->addItem(pForgotWidget, 1, 4);
//    pLayout->addItem(pRememberWidget, 2, 1, 1, 1, Qt::AlignLeft | Qt::AlignVCenter);
//    pLayout->addItem(pAutoLoginWidget, 2, 2, 1, 1, Qt::AlignRight | Qt::AlignVCenter);
//    pLayout->addItem(pLoginWidget, 3, 1, 1, 2);
//    pLayout->setHorizontalSpacing(10);
//    pLayout->setVerticalSpacing(10);
//    pLayout->setContentsMargins(10, 10, 10, 10);

//    QGraphicsWidget *pWidget = new QGraphicsWidget();
//    pWidget->setLayout(pLayout);

//    // 将 item 添加至场景中
//    pScene->addItem(pWidget);

//    // 为视图设置场景
//    QGraphicsView *pView = new QGraphicsView();
//    pView->setScene(pScene);pView->setBackgroundBrush(QBrush());
//    pView->show();

    return app.exec();
}
